<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Models\Auth;
use Illuminate\Support\Facades\Storage;

class ProfileController extends Controller
{
    public function info()
    {
    	$manager = auth('admin')->user();
    	return view('admins.profile', compact('manager'));
    }

    public function update(Request $request, Auth $admin)
    {
    	$manager = auth('admin')->user();
        $data = $request->all();
    	if(Storage::disk('public')->exists($request->avatar)){
            $data['avatar'] = Storage::url(Storage::disk('public')->put('avatars', $request->avatar));
        }
        $manager->update($data);
        return redirect()->route('admin.profile')->with(['success' => '编辑成功', 'manager' => $manager]);
    }
}
